home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************
- HTBSwitch.dll
-
- SwitchDlg.cpp
-
- Copyright 1999 TransEra Corporation
- *****************************************************/
-
- #include "stdafx.h"
- #include "HTBswitch.h"
- #include "SwitchDlg.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- #define START_SIZE_X 110
- #define START_SIZE_Y 200
- #define TIMERVAL 100
- #define GREY_COLOR 190
- #define DARK_GREY 125
- #define OUT_TXT_POS 115
- #define TOP_X 30
- #define TOP_Y 10
- #define BOTTOM_X 70
- #define BOTTOM_Y 30
- #define MEDIAN 40
- #define COLOR_MAX 255
- #define COLOR_MIN 0
- #define BOTTOM_SWITCH_POS 100
- #define TOP_SWITCH_POS 70
- #define BOTTOM_TXT_POS 37
- #define OFF_SWITCH "OFF"
- #define ON_SWITCH "ON"
-
- short sem = 0;
- int iOutlineX1 = TOP_X;
- int iOutlineY1 = BOTTOM_X;
- int iOutlineX2 = BOTTOM_X;
- int iOutlineY2 = BOTTOM_SWITCH_POS;
- int iColor1 = COLOR_MAX;
- int iColor2 = COLOR_MIN;
- int TboxXPos = BOTTOM_TXT_POS;
- CString Out_Text = OFF_SWITCH;
-
- SwitchDlg::SwitchDlg(CWnd* pParent /*=NULL*/)
- : CDialog(SwitchDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(SwitchDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
-
- void SwitchDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(SwitchDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(SwitchDlg, CDialog)
- //{{AFX_MSG_MAP(SwitchDlg)
- ON_WM_PAINT()
- ON_WM_TIMER()
- ON_WM_LBUTTONDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: SwitchDlg::OnInitDialog
-
- Description: Initializes app.
-
- Return type: BOOL
-
- Notes: This function takes the input from the user and
- starts the dialog box window in the appropriate
- X & Y locations specified, along with other
- dialof box properties. This function also calls
- the timer.
-
- */
- BOOL SwitchDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- SetWindowPos(FromHandle(m_hWnd), g_Xpos, g_Ypos, START_SIZE_X,
- START_SIZE_Y, SWP_NOZORDER);
- SetTimer(1,TIMERVAL,NULL);
- return TRUE;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: SwitchDlg::OnPaint
-
- Description: Paints the data onto the dialog box window
-
- Return type: void
-
- Notes: Paints the colors, lines and shapes onto the dialog
- box window from the dc calls.
-
- */
- void SwitchDlg::OnPaint()
- {
- CPaintDC dc(this);
- CBrush lightcolor(RGB(iColor1,iColor2,0));
- CBrush grey(RGB(GREY_COLOR,GREY_COLOR,GREY_COLOR));
- CBrush dark(RGB(DARK_GREY,DARK_GREY,DARK_GREY));
- dc.SelectObject(&lightcolor);
- dc.Rectangle(TOP_X,TOP_Y,BOTTOM_X,BOTTOM_Y);
- dc.SelectObject(&grey);
- dc.Rectangle(TOP_X,(TOP_Y + BOTTOM_SWITCH_POS),BOTTOM_X,(MEDIAN + BOTTOM_SWITCH_POS));
- dc.Rectangle(TOP_X,MEDIAN,BOTTOM_X,BOTTOM_SWITCH_POS);
- dc.SelectObject(&dark);
- dc.Rectangle(iOutlineX1,iOutlineY1,iOutlineX2,iOutlineY2);
- dc.TextOut(TboxXPos,OUT_TXT_POS,Out_Text);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: SwitchDlg::OnTimer
-
- Description: Timer function call
-
- Return type: void
- Argument: UINT nIDEvent
-
- Notes: this function updates the graphical data on the dialog box
- by invalidating it on every timer strobe.
-
- */
- void SwitchDlg::OnTimer(UINT nIDEvent)
- {
- Invalidate();
- CDialog::OnTimer(nIDEvent);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- /*
- Function: SwitchDlg::OnLButtonDown
-
- Description: takes input from left mouse button
-
- Return type: void
- Argument: UINT nFlags
- Argument: CPoint point
-
- Notes: takes input from mouse and decides whether or not
- that input needs to make the value and color of the
- switch change if it does need to change, this function
- will do so.
-
- */
- void SwitchDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
-
- int x = 0; // X position of left-Mouse click
- int y = 0; // Y position of left-Mouse click
- CPoint m_Point;
-
- m_Point = point;
- x = m_Point.x;
- y = m_Point.y;
-
- // Color and Position of the switch
- if (x > BOTTOM_Y && x < BOTTOM_X && y > MEDIAN && y < BOTTOM_X) { //ON
- iColor1 = COLOR_MIN;
- iColor2 = COLOR_MAX;
- iOutlineX1 = BOTTOM_Y;
- iOutlineY1 = MEDIAN;
- iOutlineX2 = TOP_SWITCH_POS;
- iOutlineY2 = TOP_SWITCH_POS;
- TboxXPos = MEDIAN;
- Out_Text = ON_SWITCH;
- * RetVal = 1;
- }
- // Color and Position of the switch
- if (x > BOTTOM_Y && x < BOTTOM_X && y > BOTTOM_X && y < BOTTOM_SWITCH_POS) { //OFF
- iColor1 = COLOR_MAX;
- iColor2 = COLOR_MIN;
- iOutlineX1 = BOTTOM_Y;
- iOutlineY1 = TOP_SWITCH_POS;
- iOutlineX2 = TOP_SWITCH_POS;
- iOutlineY2 = BOTTOM_SWITCH_POS;
- TboxXPos = BOTTOM_TXT_POS;
- Out_Text = OFF_SWITCH;
- * RetVal = 0;
- }
- CDialog::OnLButtonDown(nFlags, point);
- }
-